#include<pthread.h>

class mutex{
    public:
     mutex(){
       int n= pthread_mutex_init(&_mutex,nullptr);
       (void)n;
     }
      void Lock(){    pthread_mutex_lock(&_mutex);}
      void Unlock(){    pthread_mutex_unlock(&_mutex);}


     ~mutex(){
        int n= pthread_mutex_destroy(&_mutex);
        (void)n;
      }
private: 
  pthread_mutex_t _mutex;
};

class mutexguard{
    public:
    //初始化为上锁;
    mutexguard(mutex &mg):_mg(mg){  _mg.Lock() ;  }
    //析构为解锁：
    ~mutexguard(){_mg.Unlock() ;    }

     private:
     mutex &_mg;
};
